#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) Huoty, All rights reserved
# Author: Huoty <sudohuoty@gmail.com>
# CreateTime: 2018-09-28 23:09:27

def merge_ordered_lists(l1, l2):
    tmp = []
    while len(l1) > 0 and len(l2) > 0:
        if l1[0] < l2[0]:
            tmp.append(l1.pop(0))
        else:
            tmp.append(l2.pop(0))
    if l1:
        tmp.extend(l1)
    if l2:
        tmp.extend(l2)
    return tmp


if __name__ == "__main__":
    l1 = [2, 5, 8, 9]
    l2 = [1, 4, 5, 6, 8]
    print(merge_ordered_lists(l1, l2))
